package com.gba.mark.group.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.gba.mark.group.entity.Group;
import com.gba.mark.group.mapper.GroupMapper;
import com.gba.mark.group.service.IGroupService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//
//@RunWith(SpringRunner.class)
//@SpringBootTest(classes = MarkApplication.class)

@Service
public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements IGroupService {

    @Resource
    private IGroupService groupService;

    @Resource
    private GroupMapper groupMapper;

    @Transactional(
            rollbackFor = {Exception.class}
    )

//    @Override
//    public boolean skip(Integer userId){
//        Integer Admin_id = userId;
//        return true;
//    }

    @Override
    public boolean saveGroup(String Language,String name,Integer size,Integer admin_id) {

               Group group =new Group();
            //判断组名是否重复
            if (this.baseMapper.selectOne(new QueryWrapper<Group>().eq("name", group.getName())) == null) {

                //存入数据：小组名称、人数、语种、管理员
                group.setName(group.getName());
                group.setSize(group.getSize());
                group.setLanguage(group.getLanguage());
                group.setAdmin_id(group.getAdmin_id());
                groupService.save(group);
                return true;

            } else {
                System.out.println("组名重复，请重新输入：");
                return false;
            }
        }


    @Transactional(
            rollbackFor = {Exception.class}
    )

    @Override
    public boolean removeGroup( String name){
        return true;
    }

    @Override
    public boolean searchGroup(String name){
//        Group group =new Group();
//        String groupName =group.getName();
//       QueryWrapper<Group> queryWrapper =new QueryWrapper<Group>();
//       Map<String,Object> group =new HashMap<>();
//       group.put("name","");
//        queryWrapper.allEq();
//        List<Group> groupList = groupMapper.selectList((queryWrapper));
//        System.out.println(groupList);
        return true;
    }

}
